﻿namespace NumeralSystems
{
    using System;

    class ConvertRandomHexToDec
    {
        // 1.1.8.07. Write a program that converts a hexadecimal number to decimal one.

        public static int ConvertHexadecimalToDecimal(string hexNum)
        {
            int numAsDecimal = 0;
            for (int i = 0; i < hexNum.Length; i++)
            {
                if (hexNum[hexNum.Length - 1 - i] == '0')
                {
                    numAsDecimal += 0 * ConvertRandomBinaryToDecimal.CalculatePower(0, i);  // from 1.1.8.5
                }
                else if (hexNum[hexNum.Length - 1 - i] == '1')
                {
                    numAsDecimal += 1 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '2')
                {
                    numAsDecimal += 2 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '3')
                {
                    numAsDecimal += 3 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '4')
                {
                    numAsDecimal += 4 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '5')
                {
                    numAsDecimal += 5 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '6')
                {
                    numAsDecimal += 6 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '7')
                {
                    numAsDecimal += 7 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '8')
                {
                    numAsDecimal += 8 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == '9')
                {
                    numAsDecimal += 9 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == 'A')
                {
                    numAsDecimal += 10 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == 'B')
                {
                    numAsDecimal += 11 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == 'C')
                {
                    numAsDecimal += 12 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == 'D')
                {
                    numAsDecimal += 13 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == 'E')
                {
                    numAsDecimal += 14 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else if (hexNum[hexNum.Length - 1 - i] == 'F')
                {
                    numAsDecimal += 15 * ConvertRandomBinaryToDecimal.CalculatePower(16, i);
                }
                else
                {
                    throw new Exception("Error");   // my 2nd Exception as hadnt never studied about it so im a genius or an idiot
                }
            }

            return numAsDecimal;
        }

        static void Main()
        {
            string hexNum = Console.ReadLine();
            Console.WriteLine(ConvertHexadecimalToDecimal(hexNum));
        }
    }
}